<template>
  <el-form
    :inline="false"
    ref="formData"
    :model="formData"
    :rules="formDataRules"
    style="padding:20px"
    size="mini"
    label-width="100px"
  >
    <el-card>
      <span class="title-icon" style="margin-right: 1300px">基本信息</span>
      <div style="height: 50px;"></div>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="customerLoginName" label="登录名">
            <el-input
              v-model="formData.customerLoginName"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item prop="passwd" label="密码">
            <el-input
              style="margin-right: 500px"
              v-model="formData.passwd"
              clearable
              placeholder="请填密码"
            />
          </el-form-item>
        </el-col>
        <el-col :span="1">
          <el-button
            size="mini"
            v-if="!$store.state.edit.id"
            type="success"
            @click="generateMixed"
            >刷新</el-button
          >
        </el-col>

        <el-col :span="8" v-show="formData.customerType === 0 && showFlag">
          <el-form-item
            prop="whetherApprove"
            label="是否提交审批"
            label-width="160px"
          >
            <el-select v-model="formData.whetherApprove" filterable clearable>
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="customerNameShort" label="客户简称">
            <el-input
              v-model="formData.customerNameShort"
              clearable
              placeholder=""
              @input="checkCustomerNameShort"
            />
            <span style="color: red">{{tips}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="1" v-show="formData.customerType === 0 && showFlag">
          <span style="color: red;margin-left: 130px">*</span>
        </el-col>

        <el-col :span="6">
          <el-form-item prop="customerFullName" label="客户全称">
            <el-input
              v-model="formData.customerFullName"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="1">
          <el-button size="mini" type="success" @click="repeatInfo"
            >查重</el-button
          >
        </el-col>
        <el-col :span="6">
          <el-form-item prop="parentCustomerId" label="母公司">
            <el-select v-model="formData.parentCustomerId" filterable clearable>
              <el-option
                v-for="(itm, idx) in customerAllSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item prop="provincesModel" label="办公地址">
            <el-cascader
              v-model="formData.provincesModel"
              filterable
              :options="cityOptions"
              @change="cityHandleChange"
            />
            <el-input
              style="width:400px;"
              v-model="formData.businessAddress"
              clearable
              placeholder="详细地址"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="registeredAttn" label="注册联系人">
            <el-input
              v-model="formData.registeredAttn"
              clearable
              placeholder="请填写注册联系人"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="enterpriseCreditCode" label="企业信用代码">
            <el-input
              v-model="formData.enterpriseCreditCode"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-show="showFlag">
          <el-form-item
            prop="cooperateAgainTime"
            :disabled="isSearch"
            label="再次合作时间"
          >
            <el-input
              v-model="formData.cooperateAgainTime"
              :disabled="isSearch"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="registeredMobilePhoneNumber" label="注册手机号">
            <el-input
              v-model="formData.registeredMobilePhoneNumber"
              clearable
              placeholder="请填写注册手机号"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="isContract" label="是否有合同">
            <el-select
              v-model="formData.isContract"
              filterable
              clearable
              style="width: 100%"
            >
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="4" v-show="showFlag">
          <el-form-item prop="drainType" label="流失信息">
            <el-select
              v-model="formData.drainType"
              :disabled="isSearch"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in drainTypeSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="2" v-show="showFlag">
          <el-form-item prop="drainType" label="" label-width="1px">
            <el-select
              v-model="formData.drainTypeContent"
              :disabled="isSearch"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in customerDrainContentSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="4" v-show="showFlag">
          <el-form-item prop="blackType" label="黑名单信息">
            <el-select
              v-model="formData.blackType"
              :disabled="isSearch"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in blackTypeSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="2" v-show="showFlag">
          <el-form-item prop="blackType" label="" label-width="1px">
            <el-select
              v-model="formData.blackContent"
              :disabled="isSearch"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in customerBlackContentSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="position" label="职位">
            <el-select v-model="formData.position" filterable clearable>
              <el-option
                v-for="(itm, idx) in positionSource"
                :key="idx"
                :label="itm"
                :value="idx"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="legalPerson" label="法人">
            <el-input v-model="formData.legalPerson" clearable placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-show="showFlag">
          <el-form-item prop="historyCustomerServices" label="历史客服">
            <el-select
              v-model="formData.historyCustomerServices"
              :disabled="isSearch"
              multiple
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in userSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-show="showFlag">
          <el-form-item prop="historySalesmans" label="历史销售">
            <el-select
              v-model="formData.historySalesmans"
              :disabled="isSearch"
              multiple
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in userSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="18">
          <el-row>
            <el-col :span="8">
              <el-form-item prop="customerQQ" label="QQ">
                <el-input
                  v-model="formData.customerQQ"
                  clearable
                  placeholder="请填写QQ"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="contractCode" label="合同编号">
                <el-input
                  v-model="formData.contractCode"
                  clearable
                  placeholder=""
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" v-show="showFlag">
              <el-form-item
                prop="allocateTime"
                :disabled="isSearch"
                label="认领分配日期"
              >
                <el-input
                  v-model="formData.allocateTime"
                  :disabled="isSearch"
                  clearable
                  placeholder=""
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item prop="customerWeChat" label="微信">
                <el-input
                  v-model="formData.customerWeChat"
                  clearable
                  placeholder="请填写微信"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="contractLife" label="合同有效期">
                <el-date-picker
                  type="date"
                  value-format="yyyy-MM-dd"
                  v-model="formData.contractLife"
                  clearable
                  placeholder=""
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" v-show="showFlag">
              <el-form-item prop="firstDeliveryTime" label="首次发货时期">
                <el-input
                  v-model="formData.firstDeliveryTime"
                  :disabled="isSearch"
                  clearable
                  placeholder=""
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item prop="customerEmail" label="邮箱">
                <el-input
                  v-model="formData.customerEmail"
                  clearable
                  placeholder=""
                />
              </el-form-item>
            </el-col>
            <el-col :span="8" v-if="showFlag">
              <el-form-item prop="" label="其他文件">
                <span>
                  <a
                    :href="
                      `/#/main/customer__manageotherfiles__list?pid=${formData.id}`
                    "
                    target="_main"
                    style="color: blue"
                    >查看文件</a
                  >
                </span>
                <span>总数</span>
                <span>{{ fileNum }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="8" v-if="showFlag">
              <el-form-item
                prop="lastDeliveryTime"
                :disabled="isSearch"
                label="最后发货时期"
              >
                <el-input
                  v-model="formData.lastDeliveryTime"
                  :disabled="isSearch"
                  clearable
                  placeholder=""
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="6">
          <el-form-item label="备注">
            <el-input
              type="textarea"
              :rows="8"
              placeholder="请在此处备注"
              v-model="formData.remark"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="1">
          <span style="color: red;margin-left: 50px">*</span>
        </el-col>
        <el-col :span="4">
          <el-form-item prop="uploadUrl" label="营业执照/合同文件">
            <el-upload
              class="flex"
              action="#"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              :http-request="uploadBillImg"
              multiple
              :on-exceed="handleExceed"
              :file-list="fileList"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
    </el-card>
    <div style="height: 20px;"></div>
    <el-card>
      <el-row>
        <el-col :span="3">
          <span class="title-icon">基本配置</span>
        </el-col>
        <el-col :span="1" v-show="showFlag">
          <span>欠款:</span>
        </el-col>
        <el-col :span="1" v-show="showFlag">
          <span style="margin-right: 50px">{{ formData.currentDebt }}</span>
        </el-col>
      </el-row>
      <div style="height: 50px;"></div>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="accountPeriod" label="账期类型">
            <el-select v-model="formData.accountPeriod" filterable clearable>
              <el-option
                v-for="(itm, idx) in accountPeriodSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="salesman" label="销售">
            <el-select v-model="formData.salesman" filterable clearable>
              <el-option
                v-for="(itm, idx) in userSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="oceanshippingErrorRange" label="海运误差范围">
            <el-input
              type="number"
              v-model="formData.oceanshippingErrorRange"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="isCheckPrice" label="是否查价">
            <el-select v-model="formData.isCheckPrice" filterable clearable>
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="accountPeriodDate" label="账期日">
            <el-date-picker
              type="date"
              value-format="yyyy-MM-dd"
              v-model="formData.accountPeriodDate"
              clearable
              placeholder="选择日期"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="customerService" label="客服">
            <el-select v-model="formData.customerService" filterable clearable>
              <el-option
                v-for="(itm, idx) in userSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="airshippingErrorRange" label="空运误差范围">
            <el-input
              type="number"
              v-model="formData.airshippingErrorRange"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="isCesGroup" label="是否中企服">
            <el-select v-model="formData.isCesGroup" filterable clearable>
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="lastPaymentDate" label="最后还款日">
            <el-input
              type="number"
              v-model="formData.lastPaymentDate"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="customerType" label="客户类型">
            <el-select
              v-model="formData.customerType"
              :disabled="isSearch"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in customerTypeSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="isNecessaryExamine" label="入库必查">
            <el-select
              v-model="formData.isNecessaryExamine"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="customerSourceCode" label="客户来源">
            <el-select
              v-model="formData.customerSourceCode"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in customerSourceSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="lastDueDate" label="最后逾期日期">
            <el-input
              type="number"
              v-model="formData.lastDueDate"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="extendCredit" label="欠款额度">
            <el-input
              type="number"
              v-model="formData.extendCredit"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="customerLevel" label="客户等级">
            <el-select v-model="formData.customerLevel" filterable clearable>
              <el-option
                v-for="(itm, idx) in customerLevelSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="isPermit" label="欠款放行">
            <el-select v-model="formData.isPermit" filterable clearable>
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="isPushData" label="是否推送">
            <el-select v-model="formData.isPushData" filterable clearable>
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="webHook" label="API下单">
            <el-input v-model="formData.webHook" clearable placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            prop="isCustomerRealInsure"
            label="是否按客户真实货值投保"
          >
            <el-select
              v-model="formData.isCustomerRealInsure"
              filterable
              clearable
            >
              <el-option
                v-for="(itm, idx) in isOrNotSource"
                :key="parseInt(idx)"
                :label="itm"
                :value="parseInt(idx)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
        <el-form-item label="预估客户等级" prop="customerPredictLevel">
          <el-select v-model="formData.customerPredictLevel" placeholder="此客户等级由销售评估" filterable clearable>
            <el-option
              v-for="(itm, idx) in customerPredictLevelSource"
              :key="parseInt(idx)"
              :label="itm"
              :value="parseInt(idx)"
            />
          </el-select>
        </el-form-item>
        </el-col>
      </el-row>
    </el-card>
    <el-card>
      <span class="title-icon" style="margin-right: 1300px"
        >物流财务联系人</span
      >
      <div style="height: 20px;"></div>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="logisticsAttnName" label="物流联系人">
            <el-input
              v-model="formData.logisticsAttnName"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="logisticsTelephone" label="物流联系人手机">
            <el-input
              v-model="formData.logisticsTelephone"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="logisticsEmail" label="物流联系人邮箱">
            <el-input
              v-model="formData.logisticsEmail"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="logisticsQQ" label="物流联系人QQ">
            <el-input v-model="formData.logisticsQQ" clearable placeholder="" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item prop="financeAttnName" label="财务联系人">
            <el-input
              v-model="formData.financeAttnName"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="financeTelephone" label="财务联系人电话">
            <el-input
              v-model="formData.financeTelephone"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="financeEmail" label="财务联系人邮箱">
            <el-input
              v-model="formData.financeEmail"
              clearable
              placeholder=""
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="financeQQ" label="财务联系人QQ">
            <el-input v-model="formData.financeQQ" clearable placeholder="" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-card>
    <div style="height: 20px;"></div>
    <div>
      <el-button size="mini" type="primary" @click="submitForm('formData')"
        >确定</el-button
      >
    </div>
  </el-form>
</template>

<script>
import { ajax } from "@/store/yg/common/utils";
import { getPcas } from "@/utils/city-pcas.js";
import { closeDialog } from "@/utils";
import * as constant from "@/store/yg/common/constant";
import { untransform } from "@/store/yg/common/uri";
import axios from "axios";

export default {
  props: ["row", "data", "more"],
  data() {
    return {
      tips:null,
      showFlag: false,
      currentDebtShow: 1,
      fileUrl: constant.FILE_SERVER,
      examineMessage: null,
      cityOptions: getPcas(),
      customerSourceSource: {},
      customerAllSource: {},
      userSource: {},
      parentCustomerMap: {},
      accountPeriodSource: {},
      blackTypeSource: {},
      customerBlackContentSource: {},
      drainTypeSource: {},
      customerDrainContentSource: {},
      isOrNotSource: {},
      customerTypeSource: {},
      customerLevelSource: {},
      customerPredictLevelSource:{},
      positionSource: {},
      fileList: [],
      isSearch: true,
      fileNum: "",
      formData: {
        id: "",
        passwd: "",
        lastDueDate: "",
        customerPredictLevel:"",
        cooperateAgainTime: "",
        isPushData: "",
        webHook: "",
        whetherApprove: null,
        logisticsAttnName: "",
        logisticsTelephone: "",
        logisticsEmail: "",
        logisticsQQ: "",
        financeAttnName: "",
        financeTelephone: "",
        financeEmail: "",
        financeQQ: "",
        historyCustomerServices: "",
        historySalesmans: "",
        isCustomerRealInsure: "",
        enterpriseCreditCode: "",
        currentDebt: "",
        accountPeriod: "",
        lastDeliveryTime: "",
        customerLoginName: "",
        customerPassWord: "",
        parentCustomerId: "",
        customerNameShort: "",
        registeredAttn: "",
        isCheckPrice: "",
        lastPaymentDate: "",
        customerType: 0,
        extendCredit: "",
        customerLevel: "",
        oceanshippingErrorRange: "",
        airshippingErrorRange: "",
        isCesGroup: "",
        isPermit: "",
        isNecessaryExamine: "",
        accountPeriodDate: "",
        legalPerson: "",
        contractLife: "",
        firstDeliveryTime: "",
        position: "",
        drainType: "",
        drainTypeContent: "",
        blackType: "",
        blackContent: "",
        isContract: "",
        contractCode: "",
        allocateTime: "",
        historySalesman: "",
        customerService: "",
        registeredMobilePhoneNumber: "",
        customerQQ: "",
        customerWeChat: "",
        customerSourceCode: "",
        customerFullName: "",
        provincesModel: "",
        state: "",
        city: "",
        area: "",
        street: "",
        businessAddress: "",
        customerEmail: "",
        remark: "",
        salesman: "",
        uploadUrl: []
      },
      oldCustomerFullName: "",
      formDataRules: {
        customerNameShort: [
          { required: true, message: "请填写客户简称", trigger: "blur" }
        ],
        registeredAttn: [
          { required: true, message: "请填写联系人", trigger: "blur" }
        ],
        customerLoginName: [
          { required: true, message: "请填写登入名", trigger: "blur" }
        ],
        passwd: [
          { required: true, message: "请填写登入密码", trigger: "blur" }
        ],
        registeredMobilePhoneNumber: [
          { required: true, message: "请填写注册手机号", trigger: "blur" }
        ],
        customerFullName: [
          { required: true, message: "请填写客户全称", trigger: "blur" }
        ],
        enterpriseCreditCode: [
          { required: true, message: "请填写企业信用代码", trigger: "blur" }
        ],
        provincesModel: [
          { required: true, message: "请选择地址信息", trigger: "blur" }
        ],
        businessAddress: [
          { required: true, message: "请填写地址信息", trigger: "blur" }
        ],
        extendCredit: [
          { required: true, message: "请填写欠款额度", trigger: "blur" }
        ],
        salesman: [{ required: true, message: "请选择销售", trigger: "blur" }],
        customerService: [
          { required: true, message: "请选择客服", trigger: "blur" }
        ],
        oceanshippingErrorRange: [
          { required: true, message: "请填写海运误差范围", trigger: "blur" }
        ],
        airshippingErrorRange: [
          { required: true, message: "请填写空运误差范围", trigger: "blur" }
        ],
        isNecessaryExamine: [
          { required: true, message: "请选择入库必查", trigger: "blur" }
        ],
        isPermit: [
          { required: true, message: "请选择欠款放行", trigger: "blur" }
        ],
        isCheckPrice: [
          { required: true, message: "请选择是否查价", trigger: "blur" }
        ],
        legalPerson: [
          { required: true, message: "请填写法人", trigger: "blur" }
        ],
        logisticsAttnName: [
          { required: true, message: "请填写物流联系人", trigger: "blur" }
        ],
        logisticsTelephone: [
          { required: true, message: "请填写物流联系人手机号", trigger: "blur" }
        ],
        position: [{ required: true, message: "请选择职位", trigger: "blur" }],
        customerPredictLevel: [
          { required: true, message: "请选择客户等级", trigger: "blur" }
        ],
        logisticsEmail: [
          {
            required: true,
            trigger: "blur"
          },
          {
            pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
            message: "请填写正确的邮箱"
          }
        ],
        customerEmail: [
          {
            required: false,
            trigger: "blur"
          },
          {
            pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
            message: "请填写正确的邮箱"
          }
        ],
        financeEmail: [
          {
            required: false,
            trigger: "blur"
          },
          {
            pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
            message: "请填写正确的邮箱"
          }
        ]
      }
    };
  },
  mounted() {
    console.log("景来了")
    this.init();
    //点编辑请求接口
    if (this.$store.state.edit.id) {
      this.editData();
      //加载地址信息
      this.showFlag = true;
    } else {
      this.generateMixed();
    }
    // this.formData=this.data;
  },
  methods: {
    async editData() {
      const attrs = {
        class: "com.tofba.app.client.customer.CustomerInfoClient"
      };
      let res = await ajax(
        "queryById",
        {
          id: this.$store.state.edit.id
        },
        attrs
      );
      if (res !== null) {
        this.formData = res;
        this.formData.provincesModel = [
          res.state,
          res.city,
          res.area,
          res.street
        ];
        this.oldCustomerFullName = res.customerFullName;
        if (res.currentDebt == null || res.currentDebt == "") {
          this.formData.currentDebt = 0;
        }
        if (res.uploadUrl != null) {
          for (let i of res.uploadUrl) {
            this.fileList.push({
              url: i,
              name: i
            });
          }
        } else {
          this.formData.uploadUrl = [];
        }
        console.log(this.fileList);
      } else {
        this.$message.error("服务器异常");
      }
      const fileattrs = {
        class: "com.tofba.app.client.customer.CustomerFileManageClient"
      };
      let count = await ajax(
        "queryCount",
        { customerId: this.$store.state.edit.id },
        fileattrs
      );
      this.fileNum = count;
    },
    async init() {
      const attrs = {
        class: "com.tofba.app.client.customer.CustomerBalanceDetailClient"
      };
      let initRes = await ajax("init", {}, attrs);
      console.log(initRes);
      if (!initRes) {
        this.$message.error("初始化页面信息失败，请刷新重试");
        return;
      }
      this.customerSourceSource = initRes.customerSourceSource;
      this.userSource = initRes.userSource;
      this.customerAllSource = initRes.customerAllSource;
      this.isOrNotSource = initRes.isOrNotSource;
      this.customerTypeSource = initRes.customerTypeSource;
      this.customerLevelSource = initRes.customerLevelSource;
      this.customerPredictLevelSource=initRes.newCustomerLevelSource;
      this.accountPeriodSource = initRes.accountPeriodSource;
      this.blackTypeSource = initRes.blackTypeSource;
      this.customerBlackContentSource = initRes.customerBlackContentSource;
      this.drainTypeSource = initRes.drainTypeSource;
      this.customerDrainContentSource = initRes.customerDrainContentSource;
      this.positionSource = initRes.positionSource;
    },
    generateMixed() {
      var chars = [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z",
        "a",
        "b",
        "c",
        "d",
        "e",
        "f",
        "g",
        "h",
        "i",
        "j",
        "k",
        "l",
        "m",
        "n",
        "o",
        "p",
        "q",
        "r",
        "s",
        "t",
        "u",
        "v",
        "w",
        "x",
        "y",
        "z"
      ];
      var res = "";
      for (var i = 0; i < 4; i++) {
        var id = Math.floor(Math.random() * 52);
        res += chars[id];
      }
      res += Math.floor(Math.random() * 1000000);
      this.formData.passwd = res;
    },
    cityHandleChange(val) {
      console.log("this.val", val);
      if (!val) return;
      if (val[3] === "暂不选择") {
        val[3] = "";
      }
      for (let i of this.cityOptions) {
        for (let v of i.children) {
          for (let k of v.children) {
            for (let j of k.children) {
              if (j.label === "暂不选择") {
                j.label = "";
              }
            }
          }
        }
      }
      this.formData.state = val[0];
      this.formData.city = val[1];
      this.formData.area = val[2];
      this.formData.street = val[3];
    },
    //数据校验
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.save();
        } else {
          console.log("数据校验失败，不允许提交");
          return false;
        }
      });
    },
    save() {
      if (this.formData.uploadUrl.length === 0) {
        this.$message.error("请上传营业执照/合同文件");
        return;
      }
      if (
        this.formData.customerType === 0 &&
        this.showFlag == true &&
        this.formData.whetherApprove !== 0 &&
        this.formData.whetherApprove != 1
      ) {
        this.$message.error("请选择是否审批");
        return;
      }
      const attrs = {
        class: "com.tofba.app.client.customer.CustomerInfoClient"
      };
      ajax("save", this.formData, attrs).then(
        res => {
          if (res.code == 200) {
            this.$message.success("添加成功");
            closeDialog();
            location.reload();
          } else {
            if (res.message) {
              this.$message.error(res.message);
            } else {
              this.$message.error("添加失败");
            }
          }
        },
        error => {
          console.log(error);
        }
      );
    },
    repeatInfo() {
      console.log(this.formData);
      if (this.formData.customerFullName == "") {
        this.$message.error("请填写客户全称");
        return;
      }
      console.log(this.oldCustomerFullName);
      console.log(this.formData.customerFullName);
      // if(this.oldCustomerFullName==this.formData.customerFullName){
      //   this.$message.error("请填写新的客户全称");
      //   return;
      // }
      const attrs = {
        class: "com.tofba.app.client.customer.CustomerHopeClient"
      };
      ajax("customerFullNameRepeat", this.formData, attrs).then(
        res => {
          if (res.code != 200) {
            this.$message.error("客户全称已经存在,请更换");
          } else {
            this.$message.success("未发现重复信息");
          }
        },
        error => {
          console.log(error);
        }
      );
    },
    checkCustomerNameShort(){
      console.log("新----",this.formData)
      const attrs = {
        class: "com.tofba.app.client.customer.CustomerInfoClient"
      };
      ajax("checkCustomerNameShort", this.formData,attrs).then(
        res => {
          if (res.code != 200) {
            this.tips=res.message;
          }
        });
    },
    uploadBillImg(params) {
      const formData = new FormData();
      console.log("文件上传的参数", params.file);
      formData.append("items[]", params.file);
      console.log(this.$route);
      const action =
        constant.API_SERVER +
        "/api/consume/upload?uri=" +
        untransform(this.$route.params.uri) +
        "&f=uploadCustomerInfo&type=edit";
      axios({
        url: action,
        method: "post",
        data: formData,
        headers: {
          "Content-Type": "multipart/form-data"
        }
      }).then(res => {
        console.log("res :>> ", res);
        console.log(res.data.fileUrl);
        if (res.data.code === 200) {
          if (null != res.data && res.data != "" && res.data.data.fileUrl !== "") {
            this.formData.uploadUrl.push(res.data.fileUrl);
            this.fileList.push({
              url: res.data.data.fileUrl,
              name: res.data.data.fileName
            });
            console.log(this.formData.uploadUrl);
          } else {
            this.$message.error("文件上传失败");
          }
        } else {
          this.$message.error(res.data.data.message);
        }
      });
    },
    handleRemove(file, fileList) {
      if (this.fileList.length > 0) {
        for (let i = 0; i < this.fileList.length; i++) {
          if (file.name == this.fileList[i].name) {
            this.formData.uploadUrl.splice(i, 1);
            this.fileList.splice(i, 1);
            break;
          }
        }
      } else {
        this.formData.uploadUrl.splice(0);
      }
      console.log(file, this.fileList);
    },
    handlePreview(file) {
      console.log(file);
      for (let i = 0; i < this.fileList.length; i++) {
        if (file.name == this.fileList[i].name) {
          var path="";
          if(this.fileList[i].url.search("customer_business_license")==-1){
            path = (path = constant.FILE_SERVER +"customer_business_license/"+ this.fileList[i].url);
          }else{
            path = (path = constant.FILE_SERVER + this.fileList[i].url);
          }
          location.href =
            constant.API_SERVER +
            "/open/downloadFileByHttp?fileName=&path=" +
            path;
          break;
        }
      }
    },
    handleExceed(files, fileList) {},
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    imgOpen(memoImgUrl) {
      window.open(this.fileUrl + memoImgUrl);
    }
  }
};
</script>

<style scoped></style>
